package com.mycompany.lctwitter.action.message;

import java.util.List;

import javax.annotation.Resource;

import com.mycompany.lctwitter.action.AbstractAction;
import com.mycompany.lctwitter.biz.model.UserModel;
import com.mycompany.lctwitter.persist.model.Location;
import com.mycompany.lctwitter.persist.model.Message;
import com.mycompany.lctwitter.persist.service.LocationService;
import com.mycompany.lctwitter.persist.service.MessageService;

public class ListAction extends AbstractAction {

	private static final long serialVersionUID = 9216421633628524287L;

	private List<Message> messages;

	private long locationId;

	private Location location;

	@Resource
	private MessageService messageService;

	@Resource
	private LocationService locationService;

	public List<Message> getMessages() {
		return messages;
	}

	public void setLocationId(long locationId) {
		this.locationId = locationId;
	}

	public Location getLocation() {
		return location;
	}

	@Override
	public String execute() {
		locationId = locationId == 0 ? ((UserModel) session.get(LOGINED_USER)).getLocation().getId() : locationId;
		messages = messageService.listByLocation(locationId);
		location = locationService.find(locationId);
		return SUCCESS;
	}
}
